home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / System / XFD / Developer / Sources / ASM / SOS.a < prev    next >
Encoding:
Text File  |  2001-09-16  |  9.4 KB  |  505 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    SOS.asm
  3. ;  :Contents.    Sanity Operating System Decruncher for XFDMaster.Library
  4. ;  :Author.    Wepl
  5. ;  :History.    04.10.99 created
  6. ;  :Copyright.    Public Domain
  7. ;  :Language.    68000 Assembler
  8. ;  :Translator.    Barfly 2.9
  9. ;---------------------------------------------------------------------------*
  10. ;##########################################################################
  11.  
  12.     INCDIR    Includes:
  13.     INCLUDE    lvo/exec.i
  14.     INCLUDE    libraries/xfdmaster.i
  15.     
  16.     OUTPUT    Libs:xfd/SOS
  17.  
  18. MAXHUNKS    = 15        ;files with more hunks wont recognized
  19. MAXHEADER    = 20 + (4*MAXHUNKS) + 8 + 4
  20.  
  21. ;##########################################################################
  22. ;----------------------------------------
  23. ; XFD-Library-Header
  24.  
  25.         moveq    #-1,d0
  26.         rts    
  27.         dc.l    XFDF_ID        ;id
  28.         dc.w    XFDF_VERSION    ;version
  29.         dc.w    0
  30.         dc.l    0,0        ;private
  31.         dc.l    _xfdSlave1    ;first slave
  32.  
  33. ;----------------------------------------
  34. ; version string
  35.  
  36.         dc.b    '$VER: SOS 1.0 '
  37.     DOSCMD    "WDate >T:date"
  38.     INCBIN    T:date
  39.         dc.b    ' by Wepl for xfdmaster.library',0
  40.     CNOP 0,4
  41.  
  42. ;----------------------------------------
  43. ; xfdSlave-structure
  44.  
  45. _xfdSlave1    dc.l    0        ; next slave
  46.         dc.w    XFDS_VERSION    ; structure version
  47.         dc.w    36        ; req xfdmaster version
  48.         dc.l    _name1        ; cruncher name
  49.     ;    dc.w    XFDPFF_RELOC    ; cruncher flags
  50.         dc.w    XFDPFF_DATA    ; cruncher flags
  51.         dc.w    0        ; max length of special info (passwd)
  52.         dc.l    _check1        ; recog buffer routine
  53.         dc.l    _decrunch1    ; decrunch buffer routine
  54.         dc.l    0        ; segment recog routine
  55.         dc.l    0        ; segment decrunch routine
  56.         dc.w    0        ; slave ID
  57.         dc.w    0        ; replace slave ID
  58.         dc.l    MAXHEADER    ; min
  59.  
  60. ;----------------------------------------
  61. ; name of packer
  62.  
  63. _name1        dc.b    'SOS Executable (Sanity-Operating-System)',0
  64.     EVEN
  65.  
  66. ;----------------------------------------
  67. ; code to check crunched
  68. ; Übergabe :    D0 = ULONG data size
  69. ;        A0 = APTR  data
  70. ; Rückgabe :    D0 = BOOL  success
  71.  
  72. _check1        addq.w    #8,a0        ;id,name
  73.         move.l    (a0)+,d0    ;amount of hunks
  74.         cmp.l    #MAXHUNKS,d0
  75.         bhi    .no
  76.         addq.w    #8,a0        ;first,last hunk
  77.         lsl.l    #2,d0
  78.         add.l    d0,a0        ;hunk sizes
  79.         cmp.l    #$4e9,(a0)
  80.         bne    .no
  81.         moveq    #-1,d0
  82.         rts
  83.  
  84. .no        moveq    #0,d0
  85.         rts
  86.  
  87. ;----------------------------------------
  88. ; code to decrunch the file
  89. ; Übergabe :    A0 = APTR xfdBufferInfo
  90. ; Rückgabe :    D0 = BOOL success
  91.  
  92. _decrunch1    movem.l    a4-a6,-(a7)
  93.         move.l    a0,a5                ;A5 = xfdbi
  94.         move.l    (xfdbi_SourceBufLen,a5),d0
  95.         move.l    (xfdbi_SourceBuffer,a5),a0
  96.         bsr    _calcsize
  97.         moveq    #XFDERR_CORRUPTEDDATA,d1
  98.         tst.l    d0
  99.         beq    .quit
  100.         move.l    d0,(xfdbi_TargetBufLen,a5)
  101.         move.l    d0,(xfdbi_TargetBufSaveLen,a5)
  102.         move.l    (xfdbi_TargetBufMemType,a5),d1
  103.         move.l    (4).w,a6
  104.         jsr    (_LVOAllocMem,a6)
  105.         move.l    d0,(xfdbi_TargetBuffer,a5)
  106.         bne    .memok
  107.         moveq    #XFDERR_NOMEMORY,d1
  108.         bra    .quit
  109.         
  110. .memok        move.l    d0,a1
  111.         move.l    (xfdbi_SourceBuffer,a5),a0
  112.         move.l    (xfdbi_SourceBufLen,a5),d0
  113.         move.l    (xfdbi_TargetBufLen,a5),d1
  114.         bsr    _decrunch
  115.         tst.l    d0
  116.         bne    .decok
  117.         move.l    (xfdbi_TargetBufLen,a5),d0
  118.         move.l    (xfdbi_TargetBuffer,a5),a1
  119.         jsr    (_LVOFreeMem,a6)
  120.         moveq    #0,d0
  121.         moveq    #XFDERR_CORRUPTEDDATA,d1
  122.         bra    .quit
  123.  
  124. .decok    ;    move.l    d0,(xfdbi_TargetBufSaveLen,a5)
  125.         moveq    #0,d1        ;errcode
  126.         moveq    #-1,d0
  127.  
  128. .quit        move.w    d1,(xfdbi_Error,a5)
  129.         movem.l    (a7)+,a4-a6
  130.         rts    
  131.  
  132. ;--------------------------------
  133. ; Übergabe :    D0 = ULONG size of source
  134. ;        A0 = APTR source
  135. ; Rückgabe :    D0 = ULONG size decrunched
  136.  
  137. _calcsize    movem.l    d0/d2,-(a7)
  138.  
  139.         addq.l    #8,a0        ;id,name
  140.         move.l    (a0)+,d1    ;how many hunks
  141.         addq.l    #8,a0        ;first,last
  142.         lsl.l    #2,d1
  143.         add.l    d1,a0
  144.         lsr.l    #2,d1
  145.         
  146. .nexthunk    move.l    (a0)+,d0
  147.         and.l    #$3fffffff,d0    ;discard memory flags
  148.         cmp.l    #$3E9,d0    ;code
  149.         beq    .addlws
  150.         cmp.l    #$4E9,d0    ;code (Sanity Operating System)
  151.         beq    .addbytes
  152.         cmp.l    #$3EA,d0    ;data
  153.         beq    .addlws
  154.         cmp.l    #$3EB,d0    ;bss
  155.         bne    .n1
  156.         addq.l    #4,a0
  157.         bra    .nexthunk
  158. .n1        cmp.l    #$3EC,d0    ;reloc32
  159.         beq    .relocs
  160.         cmp.l    #$3F2,d0    ;end
  161.         bne    .err
  162.         subq.l    #1,d1        ;d1 = hunk counter
  163.         beq    .end
  164.         bra    .nexthunk
  165.  
  166. .corrupt
  167. .err        clr.l    (a7)
  168. .end        movem.l    (a7)+,_MOVEMREGS
  169.         rts
  170.  
  171. .addbytes    move.l    (a0)+,d0
  172.         bmi    .corrupt
  173.         cmp.l    #"IMP!",(a0)
  174.         bne    .corrupt
  175.         addq.l    #3,d0
  176.         and.w    #$fffc,d0
  177.         move.l    (4,a0),d2    ;unpacked imp! file
  178.         sub.l    d0,d2        ;difference
  179.         add.l    d2,(a7)
  180.         add.l    d0,a0
  181.         bra    .nexthunk
  182.  
  183. .addlws        move.l    (a0)+,d0
  184.         add.l    d0,d0
  185.         add.l    d0,d0
  186.         bmi    .corrupt
  187.         add.l    d0,a0
  188.         bra    .nexthunk
  189.  
  190. .relocs        move.l    (a0)+,d0    ;Anzahl der relocs
  191.         beq    .nexthunk
  192.         addq.l    #4,a0        ;Hunk auf den sich relocs beziehen
  193.         add.l    d0,d0
  194.         add.l    d0,d0
  195.         bmi    .corrupt
  196.         add.l    d0,a0
  197.         bra    .relocs
  198.  
  199. ;--------------------------------
  200. ; Defender of the crown
  201. ; Übergabe :    D0 = ULONG size of source buffer
  202. ;        D1 = ULONG size of destination buffer
  203. ;        A0 = APTR source
  204. ;        A1 = APTR destination
  205. ; Rückgabe :    D0 = BOOL success
  206.  
  207. chksrc        MACRO
  208.     cmp.l    a0,a5
  209.     bls    .bad
  210.         ENDM
  211. chkdst        MACRO
  212.     cmp.l    a1,a6
  213.     bls    .bad
  214.         ENDM
  215.  
  216. _decrunch    movem.l    d2-d7/a2-a6,-(a7)
  217.         move.l    a1,a3            ;A3 start of dest
  218.         move.l    a7,a4            ;A4 saved sp
  219.         lea    (a0,d0.l),a5        ;A5 end of source
  220.         lea    (a1,d1.l),a6        ;A6 end of dest
  221.         move.l    (a0)+,(a1)+    ;3f3
  222.         move.l    (a0)+,(a1)+    ;name
  223.         bne    .bad
  224.         move.l    (a0)+,d7        ;D7 amount hunks
  225.         move.l    d7,(a1)+
  226.         move.l    (a0)+,(a1)+    ;first
  227.         move.l    (a0)+,(a1)+    ;last
  228.         move.l    d7,d0
  229. .l1        move.l    (a0)+,(a1)+    ;hunk lengths
  230.         subq.l    #1,d0
  231.         bne    .l1
  232.  
  233. .nexthunk    chksrc
  234.         move.l    (a0)+,d0
  235.         chkdst
  236.         move.l    d0,(a1)+
  237.         and.l    #$3fffffff,d0    ;discard memory flags
  238.         cmp.l    #$3E9,d0    ;code
  239.         beq    .code
  240.         cmp.l    #$4E9,d0    ;code (Sanity Operating System)
  241.         beq    .codesos
  242.         cmp.l    #$3EA,d0    ;data
  243.         beq    .data
  244.         cmp.l    #$3EB,d0    ;bss
  245.         beq    .bss
  246.         cmp.l    #$3EC,d0    ;reloc32
  247.         beq    .reloc32
  248.         cmp.l    #$3F2,d0    ;end
  249.         bne    .bad
  250.         subq.l    #1,d7        ;d7 = hunk counter
  251.         bne    .nexthunk
  252.         
  253.         moveq    #-1,d0        ;success
  254.  
  255. .end        movem.l    (a7)+,_MOVEMREGS
  256.         rts
  257.  
  258. .bad        moveq    #0,d0
  259.         bra    .end
  260.  
  261. .codesos    sub.w    #$100,(-2,a1)
  262.         move.l    (a0)+,d2    ;packed length in bytes
  263.         move.l    (4,a0),d3    ;unpacked length
  264.         move.l    d3,d0
  265.         lsr.l    #2,d0
  266.         chkdst
  267.         move.l    d0,(a1)+
  268.         bsr    _IMP_Decrunch
  269.         tst.l    d0
  270.         beq    .bad
  271.         addq.l    #3,d2
  272.         and.w    #$fffc,d2
  273.         add.l    d2,a0
  274.         add.l    d3,a1
  275.         bra    .nexthunk
  276.  
  277. .code
  278. .data        chksrc
  279.         move.l    (a0)+,d0
  280.         chkdst
  281.         move.l    d0,(a1)+
  282.         bmi    .bad
  283.         beq    .nexthunk
  284. .data1        chksrc
  285.         chkdst
  286.         move.l    (a0)+,(a1)+
  287.         subq.l    #1,d0
  288.         bne    .data1
  289.         bra    .nexthunk
  290.  
  291. .bss        chksrc
  292.         chkdst
  293.         move.l    (a0)+,(a1)+
  294.         bra    .nexthunk
  295.  
  296. .reloc32    chksrc
  297.         chkdst
  298.         move.l    (a0)+,d0    ;Anzahl der relocs
  299.         move.l    d0,(a1)+
  300.         beq    .nexthunk
  301.         chksrc
  302.         chkdst
  303.         move.l    (a0)+,(a1)+    ;Hunk auf den sich relocs beziehen
  304. .r1        chksrc
  305.         chkdst
  306.         move.l    (a0)+,(a1)+
  307.         subq.l    #1,d0
  308.         bne    .r1
  309.         bra    .reloc32
  310.  
  311. ;----------------------------------------
  312. ;    Übergabe :    a0  =  APTR auf Source-Daten
  313. ;            a1  =  APTR auf Dest-Speicher
  314. ;    Rückgabe :    d0  =  ULONG success (NULL = Fehler)
  315. ;
  316. ;    Fileformat :    $0    dc.b    "ATN!"
  317. ;            $4    ULONG    Length unpacked
  318. ;            $8    ULONG    Length packed
  319. ;            $A    Daten...
  320.  
  321. _IMP_Decrunch    MOVEM.L    D1-A6,-(A7)
  322.         MOVEA.L    A0,A3
  323.         MOVEA.L    A1,A4
  324.         MOVEA.L    A1,A5
  325.         CMPI.L    #"IMP!",(A0)+
  326.         BNE.B    L_50
  327.         ADDA.L    (A0)+,A4
  328.         ADDA.L    (A0)+,A3
  329.         MOVEA.L    A3,A2
  330.         MOVE.L    (A2)+,-(A0)
  331.         MOVE.L    (A2)+,-(A0)
  332.         MOVE.L    (A2)+,-(A0)
  333.         MOVE.L    (A2)+,D2
  334.         MOVE.W    (A2)+,D3
  335.         BMI.B    L_26
  336.         SUBQ.L    #1,A3
  337. L_26        LEA    -$001C(A7),A7
  338.         MOVEA.L    A7,A1
  339.         MOVEQ    #6,D0
  340. L_2E        MOVE.L    (A2)+,(A1)+
  341.         DBRA    D0,L_2E
  342.         MOVEA.L    A7,A1
  343.         MOVEQ    #0,D4
  344. L_38        TST.L    D2
  345.         BEQ.B    L_42
  346. L_3C        MOVE.B    -(A3),-(A4)
  347.         SUBQ.L    #1,D2
  348.         BNE.B    L_3C
  349. L_42        CMPA.L    A4,A5
  350.         BCS.B    L_5A
  351.         LEA    $001C(A7),A7
  352.         MOVEQ    #-1,D0
  353.         CMPA.L    A3,A0
  354.         BEQ.B    L_52
  355. L_50        MOVEQ    #0,D0
  356. L_52        MOVEM.L    (A7)+,D1-A6
  357.         RTS
  358.  
  359. L_5A        ADD.B    D3,D3
  360.         BNE.B    L_62
  361.         MOVE.B    -(A3),D3
  362.         ADDX.b    D3,D3
  363. L_62        BCC.B    L_C8
  364.         ADD.B    D3,D3
  365.         BNE.B    L_6C
  366.         MOVE.B    -(A3),D3
  367.         ADDX.b    D3,D3
  368. L_6C        BCC.B    L_C2
  369.         ADD.B    D3,D3
  370.         BNE.B    L_76
  371.         MOVE.B    -(A3),D3
  372.         ADDX.b    D3,D3
  373. L_76        BCC.B    L_BC
  374.         ADD.B    D3,D3
  375.         BNE.B    L_80
  376.         MOVE.B    -(A3),D3
  377.         ADDX.b    D3,D3
  378. L_80        BCC.B    L_B6
  379.         ADD.B    D3,D3
  380.         BNE.B    L_8A
  381.         MOVE.B    -(A3),D3
  382.         ADDX.b    D3,D3
  383. L_8A        BCC.B    L_92
  384.         MOVE.B    -(A3),D4
  385.         MOVEQ    #3,D0
  386.         BRA.B    L_CC
  387.  
  388. L_92        ADD.B    D3,D3
  389.         BNE.B    L_9A
  390.         MOVE.B    -(A3),D3
  391.         ADDX.b    D3,D3
  392. L_9A        ADDX.b    D4,D4
  393.         ADD.B    D3,D3
  394.         BNE.B    L_A4
  395.         MOVE.B    -(A3),D3
  396.         ADDX.b    D3,D3
  397. L_A4        ADDX.b    D4,D4
  398.         ADD.B    D3,D3
  399.         BNE.B    L_AE
  400.         MOVE.B    -(A3),D3
  401.         ADDX.b    D3,D3
  402. L_AE        ADDX.b    D4,D4
  403.         ADDQ.B    #6,D4
  404.         MOVEQ    #3,D0
  405.         BRA.B    L_CC
  406.  
  407. L_B6        MOVEQ    #5,D4
  408.         MOVEQ    #3,D0
  409.         BRA.B    L_CC
  410.  
  411. L_BC        MOVEQ    #4,D4
  412.         MOVEQ    #2,D0
  413.         BRA.B    L_CC
  414.  
  415. L_C2        MOVEQ    #3,D4
  416.         MOVEQ    #1,D0
  417.         BRA.B    L_CC
  418.  
  419. L_C8        MOVEQ    #2,D4
  420.         MOVEQ    #0,D0
  421. L_CC        MOVEQ    #0,D5
  422.         MOVE.W    D0,D1
  423.         ADD.B    D3,D3
  424.         BNE.B    L_D8
  425.         MOVE.B    -(A3),D3
  426.         ADDX.b    D3,D3
  427. L_D8        BCC.B    L_F0
  428.         ADD.B    D3,D3
  429.         BNE.B    L_E2
  430.         MOVE.B    -(A3),D3
  431.         ADDX.b    D3,D3
  432. L_E2        BCC.B    L_EC
  433.         MOVE.B    L_150(PC,D0.W),D5
  434.         ADDQ.B    #8,D0
  435.         BRA.B    L_F0
  436.  
  437. L_EC        MOVEQ    #2,D5
  438.         ADDQ.B    #4,D0
  439. L_F0        MOVE.B    L_154(PC,D0.W),D0
  440. L_F4        ADD.B    D3,D3
  441.         BNE.B    L_FC
  442.         MOVE.B    -(A3),D3
  443.         ADDX.b    D3,D3
  444. L_FC        ADDX.w    D2,D2
  445.         SUBQ.B    #1,D0
  446.         BNE.B    L_F4
  447.         ADD.W    D5,D2
  448.         MOVEQ    #0,D5
  449.         MOVEA.L    D5,A2
  450.         MOVE.W    D1,D0
  451.         ADD.B    D3,D3
  452.         BNE.B    L_112
  453.         MOVE.B    -(A3),D3
  454.         ADDX.b    D3,D3
  455. L_112        BCC.B    L_12E
  456.         ADD.W    D1,D1
  457.         ADD.B    D3,D3
  458.         BNE.B    L_11E
  459.         MOVE.B    -(A3),D3
  460.         ADDX.b    D3,D3
  461. L_11E        BCC.B    L_128
  462.         MOVEA.W    8(A1,D1.W),A2
  463.         ADDQ.B    #8,D0
  464.         BRA.B    L_12E
  465.  
  466. L_128        MOVEA.W    (A1,D1.W),A2
  467.         ADDQ.B    #4,D0
  468. L_12E        MOVE.B    $0010(A1,D0.W),D0
  469. L_132        ADD.B    D3,D3
  470.         BNE.B    L_13A
  471.         MOVE.B    -(A3),D3
  472.         ADDX.b    D3,D3
  473. L_13A        ADDX.l    D5,D5
  474.         SUBQ.B    #1,D0
  475.         BNE.B    L_132
  476.         ADDQ.W    #1,A2
  477.         ADDA.L    D5,A2
  478.         ADDA.L    A4,A2
  479. L_146        MOVE.B    -(A2),-(A4)
  480.         SUBQ.B    #1,D4
  481.         BNE.B    L_146
  482.         BRA.W    L_38
  483.  
  484. L_150        DC.B    6
  485.         DC.B    $A
  486.         DC.B    $A
  487.         DC.B    $12
  488. L_154        DC.B    1
  489.         DC.B    1
  490.         DC.B    1
  491.         DC.B    1
  492.         DC.B    2
  493.         DC.B    3
  494.         DC.B    3
  495.         DC.B    4
  496.         DC.B    4
  497.         DC.B    5
  498.         DC.B    7
  499.         DC.B    $E
  500.  
  501. ;##########################################################################
  502.  
  503.     END
  504.  
  505.